//@author wtfumlomglol
package amm.Graphic;

import java.io.*;
import java.util.*;

//osztaly egy kozlekedo rendor leirasara
public class Police extends Citizen {

    //rendornek szuksege van a jatek referenciajara,
    //ha az mar megallt, mert elkapta a bankrablot,
    //ne kezdjen feleslegesen mozogni
    public Police(Game game, int index) {
        g = game;
        if (g!=null) logger=g.getLogger();
        name = "Police[" + index + "]";
        tempo=1;
    }

    //a rendor ugyanugy mozog, mint a civil
    @Override
    public void moveTo(Field f) {
        Field prev = occupies;

        if (prev != f) {
            occupies = f;
            Place place;
            boolean stopSign;
            logger.addMessage("Police moved to " + f.getName());
            if (prev != null) {
                prev.clear();
            }
            place = occupies.getPlace();
            if (place == Place.ROAD) {
                Road rd = (Road) occupies;
                stopSign = rd.getSign();
                if (stopSign) {
                    stopCount = 1;
                }
            }
        } else {
            logger.addMessage("Police didn't move.");
        }
    }

    //a rendor kore harom fazisbol all
    //1. korbenez, hogy van-e a szomszedos mezokon bankrablo
    //2. civil modon lep
    //3. ismet ellenoriz
    @Override
    public void onTick() {

        occupies.bustCriminal();
        if (!g.isRunning()) {
            return;
        }
        if (stopCount==0)
        {
            occupies.leave(true, null);
        }
        else stopCount--;
        occupies.bustCriminal();
    }

    @Override
    public String getMark()
    {
        return "P";
    }
}
